<?php
$_SESSION['steps'][$_GET['action']] = false;
if($_SESSION['index']=='')
{
	displayError('Une erreur interne s\'est produit (perte du fichier index.xml)');
}
if(isset($_GET['post']) && $_GET['post']==1)
{
	include_once($temp_path.'/setup_archive.php5');
	
	$setup = new SimpleXMLElement($_SESSION['index']);

	$tgz = new gzip_file($_SESSION['pack_path']);
	session_write_close();

	$errors = array();
	$nb = count($setup->screens[0]->extractfile);
	foreach ($setup->screens[0]->extractfile as $index => $extract)
	{
		$tgz->set_options(array('basedir' => $current_path.'/'.$extract['serverpath'], 'overwrite' => 1));
		$result = $tgz->extract_files(array(array($extract['tarpath'], '*')), array(($index*1000)/$nb, (($index+1)*1000)/$nb));
		if($result === false)
		{
?>
ajax.sendAsync(page+'?action=copy_file&post=1&uid='+new Date().getTime(), function(datas)
{
	eval(datas)
})
<?php			
			die();
		}
		else 
		{
			list($n_errors, $n_succes) = $result;
		}

		$errors = array_merge($errors, $n_errors);
	}
	if(count($setup->deleted)>0)
	{
		foreach ($setup->deleted[0]->path as $path)
		{
			if(is_dir($current_path.$path))
			{
				@rmdir($current_path.$path);
			}
			elseif(is_file($current_path.$path))
			{
				unlink($current_path.$path);
			}
		}
	}
	session_start();
	if(count($errors)>0)
	{
		$message = 'Erreur lors de l\'extraction de l\'archive<br><br>'.implode('<br>', $errors);
		displayButtons();
?>
document.getElementById('install_content_data').innerHTML = '<span class="install_message_error"><?php echo strToJs($message)?></span>';
document.getElementById('install_next').disabled=true;
<?php
		die();
	}
?>
clearTimeout(to)
document.getElementById("div_file").style.width = "100%";
document.getElementById("div_file_label").innerHTML = "100%";
<?php
	displayButtons();
	$_SESSION['steps'][$_GET['action']] = true;
?>
	document.getElementById('install_next').onclick();
<?php
}
else 
{
	$_SESSION['progress'] = 0;
?>
document.getElementById('install_content_intro').innerHTML = 'Veuillez patienter pendant que l\'installer copie les fichiers.';
document.getElementById('install_content_data').innerHTML = '<div style="position:absolute;top:5px;left:10px;right:10px;border:1px solid #606060"><div style="background-color:#6999DA;width:1px;height:16px;overflow:hidden" id="div_file">&nbsp;</div><div style="position:absolute;left:0px;top:0px;right:0px;bottom:0px;text-align:center; font-weight:bold;" id="div_file_label">&nbsp;</div></div>'
document.getElementById('install_next').style.display='none'
document.getElementById('install_back').style.display='none'

ajax.sendAsync(page+'?action=copy_file&post=1&uid='+new Date().getTime(), function(datas)
{
	eval(datas)
})
ajax.sendAsync(page+'?action=copy_file_info&uid='+new Date().getTime(), function(datas)
{
	evalAjax(datas)
})
<?php
}
?>